import 'package:flutter/material.dart';

class LoadingDialog extends Dialog {
  final double height;
  final double width;
  final String? title;// 内容文本
  final bool isCancel;// 是否点击外部或者返回键关闭Dialog
  final Color color;// 内容背景颜色
  final BorderRadiusGeometry? borderRadius;// 内容倒角半径
  final EdgeInsetsGeometry? padding;// 内容内边距
  final Color textColor;// 文本颜色
  final double textSize;// 字体大小

  const LoadingDialog({
    Key? key,
    this.width=100.00,
    this.height=100.00,
    this.title,
    this.isCancel = false,
    this.textSize = 12,
    this.color=Colors.black,
    this.borderRadius,
    this.padding,
    this.textColor=Colors.white
  }):super(key: key);

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return WillPopScope(
      onWillPop: () async => isCancel,// 拦截Android返回键
      child: GestureDetector(
        onTap: ()=>{

        },
        child: Material(
          type: MaterialType.transparency,
          child: Center(
            child: Container(
              decoration: ShapeDecoration(
                  color: color,
                  shape: RoundedRectangleBorder(
                      borderRadius: borderRadius!=null?borderRadius!:const BorderRadius.all(Radius.circular(10)))),
              width: width,
              height: height,
              padding: padding!=null?padding!:const EdgeInsets.all(10),
              child: Column(mainAxisAlignment: MainAxisAlignment.spaceEvenly,children: [
                 CircularProgressIndicator(color: textColor,strokeWidth: 1,),
                Text(title==null?"加载中":title!,style: TextStyle(fontSize: textSize,color: textColor),softWrap: false,)
              ],),
            ),
          ),
        ),
      )
    );
  }


  static void show(BuildContext context,{String? title}){
    showDialog(context: context, builder: (context)=>LoadingDialog(title: title));
  }

  static void close(BuildContext context){
    Navigator.of(context).pop();
  }

}
